CREATE TABLE [dbo].[tb_Turnos]
(
[idTurno] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Mnemo] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updatetb_Turnos] ON [dbo].[tb_Turnos]
 FOR UPDATE AS 
SET NOCOUNT ON
 IF (update(idTurno)) begin 
	 SELECT * FROM inserted 
	 IF @@ROWCOUNT = 1 begin 
		 UPDATE tb_Plazas
		 SET Turno = (SELECT idTurno FROM inserted)
		 WHERE tb_Plazas.Turno = (SELECT idTurno FROM deleted)
		 UPDATE tb_AperturasDeReestructura
		 SET Turno = (SELECT idTurno FROM inserted)
		 WHERE tb_AperturasDeReestructura.Turno = (SELECT idTurno FROM deleted)
	end  ELSE begin 
		 ROLLBACK TRANSACTION 
 end 
 end

GO
ALTER TABLE [dbo].[tb_Turnos] ADD CONSTRAINT [PK_tb_Turnos] PRIMARY KEY CLUSTERED  ([idTurno]) ON [PRIMARY]
GO
